﻿
namespace TinyMceWrapper.Web.Configuration
{

    #region [ Imports ]

    using System.Configuration;
    using System.Diagnostics.CodeAnalysis;

    #endregion

    [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mce")]
    public sealed class TinyMceSection : ConfigurationSection
    {

        #region [ Local Fields ]

        private static readonly ConfigurationProperty _scriptPath = new ConfigurationProperty("scriptPath", typeof(string), null, null, new StringValidator(1), ConfigurationPropertyOptions.IsRequired);
        private static readonly ConfigurationProperty _scriptMode = new ConfigurationProperty("scriptMode", typeof(string));
        private static readonly ConfigurationProperty _displatModes = new ConfigurationProperty("displayModes", typeof(TinyMceDisplayModeCollection));
        private static readonly ConfigurationPropertyCollection _properties = new ConfigurationPropertyCollection();

        #endregion

        #region [ Constructors ]

        [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
        static TinyMceSection()
        {
            _properties.Add(_scriptPath);
            _properties.Add(_scriptMode);
            _properties.Add(_displatModes);
        }

        #endregion

        #region [ Public Properties ]

        [ConfigurationProperty("scriptPath", IsRequired = true), StringValidator(MinLength = 1)]
        public string ScriptPath
        {
            get { return (string)this[_scriptPath]; }
            set { this[_scriptPath] = value; }
        }

        [ConfigurationProperty("scriptMode")]
        public string ScriptMode
        {
            get { return (string)this[_scriptMode]; }
            set { this[_scriptMode] = value; }
        }

        [ConfigurationProperty("displayModes")]
        public TinyMceDisplayModeCollection DisplayModes
        {
            get { return (TinyMceDisplayModeCollection)this[_displatModes]; }
        }

        protected override bool OnDeserializeUnrecognizedAttribute(string name, string value)
        {
            return (name == "xmlns");
        }

        #endregion

        #region [ Overriden Members ]

        protected override ConfigurationPropertyCollection Properties
        {
            get { return _properties; }
        }

        #endregion

    }

}
